$(document).ready(function(){
	$('.error').delay(4000);
	$('.error').fadeOut('slow'); // reset the error messages (hides them)
	$('.error_msg').delay(4000);
	$('.error_msg').fadeOut('slow'); // reset the error messages (hides them)
	$('.success_msg').delay(4000);
	$('.success_msg').fadeOut('slow'); // reset the error messages (hides them)
	$("#peronal_select").click(function(){
		$("#personal_div").show();
		$("#edu_div").hide();
		$("#doc_div").hide();
		$("#refree_div").hide();
		$("#peronal_select").removeClass( "active" ).addClass("active");
		$("#edu_select").removeClass( "active" );
		$("#doc_select").removeClass( "active" );
		$("#refree_select").removeClass( "active" );
		$("#applicant_form_submit_doc").hide();
	});
	$("#edu_select").click(function(){
		if($("#app_submit").val() == '0')
		{
			$("#err-top").html('Please fill in the personal details first');
			$("#err-top").show(500);
			$("#err-top").delay(4000);
			$("#err-top").animate({
			   height: 'toggle'  
			}, 500, function() {
			   // Animation complete.
			});
		}
		else{
			$("#personal_div").hide();
			$("#edu_div").show();
			$("#doc_div").hide();
			$("#refree_div").hide();
			$("#peronal_select").removeClass( "active" );
			$("#edu_select").removeClass( "active" ).addClass("active");
			$("#doc_select").removeClass( "active" );
			$("#refree_select").removeClass( "active" );
			$("#applicant_form_submit_doc").hide();
		}
	});
	$("#doc_select").click(function(){
		if($("#app_submit").val() == '0')
		{
			$("#err-top").html('Please fill in the personal details first');
			$("#err-top").show(500);
			$("#err-top").delay(4000);
			$("#err-top").animate({
			   height: 'toggle'  
			}, 500, function() {
			   // Animation complete.
			});
		}
		else{
			$("#personal_div").hide();
			$("#edu_div").hide();
			$("#doc_div").show();
			$("#refree_div").hide();
			$("#peronal_select").removeClass( "active" );
			$("#edu_select").removeClass( "active" );
			$("#doc_select").removeClass( "active" ).addClass("active");
			$("#refree_select").removeClass( "active" );
			$("#applicant_form_submit_doc").show();
		}
	});
	$("#refree_select").click(function(){
		if($("#app_submit").val() == '0')
		{
			$("#err-top").html('Please fill in the personal details first');
			$("#err-top").show(500);
			$("#err-top").delay(4000);
			$("#err-top").animate({
			   height: 'toggle'  
			}, 500, function() {
			   // Animation complete.
			});
		}
		else{
			$("#personal_div").hide();
			$("#edu_div").hide();
			$("#doc_div").hide();
			$("#refree_div").show();
			$("#peronal_select").removeClass( "active" );
			$("#edu_select").removeClass( "active" );
			$("#doc_select").removeClass( "active" );
			$("#refree_select").removeClass( "active" ).addClass("active");
			$("#applicant_form_submit_doc").hide();
		}
	});
	
	/*$("#applicant_form_submit_personal").click(function(){
		$("#user_application_form").submit();
	});
	$("#applicant_form_submit_edu").click(function(){
		$("#user_application_edu_form").submit();
	});
	$("#applicant_form_submit_doc").click(function(){
		$("#user_application_doc_form").submit();
	});
	*/
	/*$("#applicant_form_submit_refree").click(function(){
		$("#user_application_refree_form").submit();
	});*/
	/*$("#nom_form_submit_nominating").click(function(){
		
		
		$("#user_nomination_form").submit();
	});
	$("#applicant_form_submit_nominee").click(function(){
		$("#user_nomination_nominee_form").submit();
	});*/
	$("#applicant_form_submit_disclosure").click(function(){
		$("#user_nomination_dis_form").submit();
	});
});

function validateForm(val_id)
{
	var regex = /^\s*[a-zA-Z0-9_.@\-\s]+\s*$/;
	var name = '#'+val_id;
	var man = '#man-'+val_id;
	if($(name).val() == ''  && $(man).val() == '1')
	{
		$(name).focus();
		$("#err-"+val_id).html('This filed is mandatory');
		$("#err-"+val_id).show(500);
		$("#err-"+val_id).delay(4000);
		$("#err-"+val_id).animate({
		   height: 'toggle'  
		}, 500, function() {
		   // Animation complete.
		});         
	}
	else if($(name).val() != ''  && regex.test($(name).val())==false)
	{
		$(name).focus();
		$("#err-"+val_id).html('Please enter a valid entry');
		$("#err-"+val_id).show(500);
		$("#err-"+val_id).delay(4000);
		$("#err-"+val_id).animate({
		   height: 'toggle'  
		}, 500, function() {
		   // Animation complete.
		});         
	}
}
